package com.wondream.myframework.io;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class FileReaderWriterTest {

    Log logger = LogFactory.getLog(FileReaderWriterTest.class);

    public static void main(String[] args) {
        FileReader fr = null;
        FileWriter fw = null;
        try{
            File file = new File("./logs/fileReaderWriter.txt");
            fw = new FileWriter(file);
            fw.write("我是渣渣辉！");
            fw.flush();
            fr = new FileReader(file);
            int dataLen = -1;
            int bufferLen = 1024*100;
            char[] buffer = new char[bufferLen];
            if((dataLen = fr.read(buffer, 0, bufferLen))!=-1){
                System.out.println(new String(buffer, 0, dataLen));
            }
        } catch (Exception e){

        } finally {
            try {
                if(fr!=null){
                    fr.close();fr = null;
                }
                if(fw!=null){
                    fw.close();fw = null;
                }
            } catch (Exception e){}
        }
    }

}
